"""
主板信息
"""
from ResponseData import ResponseData
from lib.plugins.BasePlugin import BasePlugin


class MainBoard(BasePlugin):
    def process(self, ssh_func, hostname):
        res = ResponseData()
        try:
            cmd = 'dmidecode -t1'
            output = ssh_func(hostname, cmd)
            res.data = self.parse(output)
        except Exception as e:
            res.status = 500
            res.msg = "error"
        return res.__dict__

    # 对返回的数据进行解析
    def parse(self, content):
        result = {}
        key_map = {
            'Manufacturer': 'manufacturer',
            'Product Name': 'model',
            'Serial Number': 'sn'
        }
        for item in content.split('\n'):
            row_data = item.strip().split(':')
            if len(row_data) == 2:
                if row_data[0] in key_map:
                    result[key_map[row_data[0]]] = row_data[1].strip() if row_data[1] else row_data[1]
        return result
